//添加购物车的方法
function addCars(goodsid,num) {
    return $.post(
        "/lengmou/user/addCars",
        {num:num,goodsid:goodsid},
        "json"
    );
}
function setCarsNum(carid,num) {
    return $.post(
        "/lengmou/user/setCarsNum",
        {carid:carid,num:num},
        "json"
    );
}

function deleteCars(carid) {
   return $.post(
        "/lengmou/user/deleteCars",
        {carid:carid},
        "json"
    );
}
function check() {
    var $tr= $(".carts-box").find(".cart-item-box");
    var goodsNum=0;
    var p = 0;
    $tr.each(function () {
        var danjia = parseFloat($(this).find("#price-one").html());
        var num = parseInt($(this).find("#num").val());
        var price=(danjia*num).toFixed(2);
        $(this).find(".price-item").html(price);
        if($(this).find('input[action="单选"]').prop('checked')){
            p+=parseFloat(price);
            goodsNum+=num;
        }
    });
    $(".cart-all-price-number").html(p.toFixed(2));
    $(".cart-checked-number").html(goodsNum);

}
function checkedState() {
    var falg = $('input[action="全选"]').prop('checked');
    var $dan = $('input[action="单选"]');
    var num = 0;
    $dan.each(function () {
        if($(this).prop('checked')){
            num++;
        }else{
            num--;
        }
    });
    if(num==$dan.length){
        $('input[action="全选"]').prop('checked',true);
    }else{
        $('input[action="全选"]').prop('checked',false);
    }
}

//获取选中的商品id
function getCarsid() {
    var $dan = $('input[action="单选"]');
    var $carsid=new Array();
    $dan.each(function () {
        if($(this).prop('checked')){
            var carid = $(this).attr("data-id");
            $carsid.push(carid);
        }
    })
    return $carsid;
}
function buy($carsid) {
    if($carsid.length!=0){
        $.post(
            "addConfirm",
            {
                carsids:$carsid
            },function (data) {
                if(data.state>0){
                    location.href="confirmByCar"
                }else{

                }
            },"json"
        )

    }

}


